/****************************************************************



******************************************************************/

#ifndef SRC_USER_USER_STRUCT_H_
#define SRC_USER_USER_STRUCT_H_

#include "HeaderFiles.h"

typedef float float32_t;

typedef enum
{
  HAL_MTR_1 = 0,
  HAL_MTR_2 = 1
	
}HAL_MotorNum_e;



// ---------------- threshold parameter struct ---------------
typedef struct
{
	uint16_t hardware_version_num;
	uint16_t software_version_num;
	
	
	uint32_t led_periph;
	uint32_t led_num;

}STR_PRARM;

// ----------------- System Fault Struct -------------------
typedef union
{
    struct
    {
        // byte 1 -----------------
        uint16_t OCP_L       :1;
        uint16_t OCP_R       :1;
        uint16_t OCP_MAIN    :1;
        uint16_t OCP_EDGE    :1;
		uint16_t reserve1    :1;
		uint16_t OCP_FAN     :1;
		
		uint16_t OVP         :1;
        uint16_t UVP         :1;
		
        // byte 2 -----------------
        uint16_t OSP_L       :1;
		uint16_t OSP_R       :1;
		
        uint16_t cancomm     :1;
        uint16_t scicomm     :1;
		
		uint16_t bumper      :1;
		uint16_t wheellift   :1;
		
        uint16_t reserve2    :2;

        // byte 3 -----------------
        uint16_t cursensor_L :1;
        uint16_t cursensor_R :1;
        uint16_t cursensor_M :1;
		uint16_t cursensor_E :1;
		uint16_t cursensor_F :1;
		
		uint16_t locked_Lbrush  :1;
		uint16_t locked_Mbrush  :1;
		uint16_t locked_Fan     :1;

        // byte 4 -----------------
        uint16_t reserve4    :8;
		
    }bit;

    uint32_t all;

}STR_FAULT;


typedef union
{
    struct
    {
        // byte 1 -----------------
        uint16_t OCP_L       :1;
        uint16_t OCP_R       :1;
        uint16_t OCP_MAIN    :1;
        uint16_t OCP_EDGE    :1;
		uint16_t reserve1    :1;
		uint16_t OCP_FAN     :1;
		
		uint16_t OVP         :1;
        uint16_t UVP         :1;
		
        // byte 2 -----------------
        uint16_t OSP_L       :1;
		uint16_t OSP_R       :1;
		
        uint16_t cancomm     :1;
        uint16_t scicomm     :1;

        uint16_t reserve2    :4;

    }bit;

    uint16_t all;

}STR_WARN;

typedef struct
{

    int16_t flt_OCP_L[2];
    int16_t flt_OCP_R[2];
    int16_t flt_OCP_M[2];
	int16_t flt_OCP_E[2];
	int16_t flt_OCP_F[2];
    int16_t flt_OVP[2];
    int16_t flt_UVP[2];
    int16_t flt_OSP_L[2];
	int16_t flt_OSP_R[2];
	
	int16_t bumper;
	int16_t wheellift;
	int16_t commtimeout;

}STR_DIAG;



typedef struct
{
    uint16_t   FSM;
    uint16_t   enable;
	
	uint8_t    ctrlmode;
	uint8_t    en_leftmop;
	uint8_t    en_rightmop;
	uint8_t    en_dustfan;
	uint8_t    en_mainbrush;
	uint8_t    en_edgebrush;
	
	uint8_t    break_shield;
	uint8_t    break_sort;
	
	uint8_t    cliff_shield;
	uint8_t    bumper_shield;
	
	uint8_t    systemstop;
	
	
	uint8_t    en_turn_left;
	uint8_t    en_turn_right;
	uint8_t    out_turn_left;
	uint8_t    out_turn_right;
	
	uint8_t    en_buzzer_x1;
	uint8_t    times_buzzer_x1;
	uint8_t    holdtime_buzzer_x1;
	
	uint8_t    en_buzzer_x2;
	uint8_t    times_buzzer_x2;
	uint8_t    holdtime_buzzer_x2;	
	
	uint8_t    type_LED_left;
	uint8_t    type_LED_right;
	
	uint16_t   pwm_cmpa[2];
	
	uint8_t    charge_relay;
	uint8_t    charge_hold;
	
	uint8_t    en_waste_pump;
	uint8_t    en_actuate_X1;
	uint8_t    en_actuate_X2;
	

}STR_CTRL;

typedef struct
{
    uint16_t vdc_plate;
	uint16_t idc;
	
	uint16_t vdc_charge;
	uint16_t level_X1;
	uint16_t level_X2;
	
	uint16_t water_X1;
	uint16_t water_X2;
		
	uint16_t temp_x1;
	uint16_t temp_x2;
	
}STR_ADC;

typedef struct
{
    float32_t vdc_plate;
	float32_t idc;
	
	float32_t vdc_charge;
	float32_t level_X1;
	float32_t level_X2;
	
	float32_t water_X1;
	float32_t water_X2;
		
	float32_t temp_x1;
	float32_t temp_x2;

}STR_REAL;



typedef struct
{
    STR_ADC  rslt;
    STR_REAL real;

	float32_t DC_power_W;
	
	uint8_t   infrared[6];
	
	uint8_t   ledstatus;
	
	uint8_t   chargestatus;
	
	uint8_t   charge_service;
	uint8_t   charge_clean;
	
	uint8_t   power_12V;
	
	uint8_t   bumper[2];
	uint8_t   bumper_status;
	uint8_t   bumper_last;
	uint8_t   break_key;
	uint8_t   start_key;
	uint8_t   power_key;
	uint8_t   break_sort;
	
	uint8_t   key_status;
	uint8_t   key_status_last;
		
	float32_t battery_level;
	
	uint8_t   chargeSignal[4];
	
	uint16_t  tof050_mm[6];
	uint8_t   cliff_flg[6];
	
	uint16_t  KS104_mm[10];
	
	
	// --------------------------
	
	uint8_t   limit_X1;
	uint8_t   limit_X2;
	uint8_t   charge_status;
	

}STR_OBSDATA;




typedef struct
{
    uint16_t runflg;

    uint16_t cycflg_1ms;
    uint16_t cycflg_1s;

    uint16_t ledBlkPrd;
	
	uint8_t  printfenable[15];
	
	
}STR_ASSIS;


// ------------------- user handle struct -------------------
typedef struct
{
    STR_CTRL       ctrl;
    STR_OBSDATA    signal;
    STR_FAULT      fault;
    STR_WARN       warn;
    STR_ASSIS      assis;
	STR_PRARM      param;

}STR_USERHDL;

extern STR_USERHDL userHdl;


extern STR_RINGBUF *KS104_REC_Buff;
extern STR_RINGBUF *KS104_TAR_Buff;
extern STR_RINGBUF *TOF050_REC_Buff;
extern STR_RINGBUF *TOF050_TRA_Buff;


#endif /* SRC_USER_USER_STRUCT_H_ */
